#include <cppunit/config/SourcePrefix.h>

#include "SynonymTable.h"
#include "TestSynonymTable.h"

void SynonymTableTest::setUp() {
	cout << "Test SynonymTable setUp()\n";
}

void SynonymTableTest::tearDown() {
}

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( SynonymTableTest );

// method to test the constructor
void SynonymTableTest::testConstructor() {
	// Just to ensure it does not produce errors
	SynonymTable synTable;
}

// Tests the getDesignEntityType function
void SynonymTableTest::testGetDesignEntityType() {
	SynonymTable synTable;

	// Add a synonym
	CPPUNIT_ASSERT(true == synTable.addSynonym(ASSIGN, "a"));
	
	// Try to get it
	CPPUNIT_ASSERT(ASSIGN == synTable.getDesignEntityType("a"));
	CPPUNIT_ASSERT(INVALID_DESIGN_ENTITY == synTable.getDesignEntityType("b")); // b doesn't exist
}

// Tests the addSynonym function
void SynonymTableTest::testAddSynonym() {
	SynonymTable synTable;

	CPPUNIT_ASSERT(true == synTable.addSynonym(ASSIGN, "a"));
	CPPUNIT_ASSERT(false == synTable.addSynonym(ASSIGN, "a"));
	CPPUNIT_ASSERT(false == synTable.addSynonym(CALL, "a"));
}

// Tests the getNumberOfSynonyms function
void SynonymTableTest::testGetNumberOfSynonyms() {
	SynonymTable synTable;

	CPPUNIT_ASSERT(true == synTable.addSynonym(ASSIGN, "a"));
	CPPUNIT_ASSERT(false == synTable.addSynonym(ASSIGN, "a"));
	CPPUNIT_ASSERT(false == synTable.addSynonym(CALL, "a"));
	CPPUNIT_ASSERT(true == synTable.addSynonym(VARIABLE, "v"));

	CPPUNIT_ASSERT_EQUAL(2, synTable.getNumberOfSynonyms());
}

// Tests the getSynonymAtIndex function
void SynonymTableTest::testGetSynonymAtIndex() {
	SynonymTable synTable;

	CPPUNIT_ASSERT(true == synTable.addSynonym(ASSIGN, "a"));
	CPPUNIT_ASSERT(false == synTable.addSynonym(ASSIGN, "a"));
	CPPUNIT_ASSERT(false == synTable.addSynonym(CALL, "a"));
	CPPUNIT_ASSERT(true == synTable.addSynonym(VARIABLE, "v"));

	CPPUNIT_ASSERT_EQUAL(string("a"), synTable.getSynonymAtIndex(0));
	CPPUNIT_ASSERT_EQUAL(string("v"), synTable.getSynonymAtIndex(1));
}